package controlador;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Iterator;

import vista.VistaJuego;

import modelo.interfaces.Manejador;
import modelo.juego.Juego;
import modelo.mapa.Posicion;
import modelo.obstaculos.CreadorObstaculo;
import modelo.obstaculos.CreadorObstaculoPegote;
import modelo.obstaculos.ManejadorObstaculos;

public class ControladorPegote implements MouseListener, MouseMotionListener {
	private ManejadorObstaculos mo; 
		
	public ControladorPegote() {
		Iterator<Manejador> it = Juego.ObtenerJuego().getManejables().iterator();
		 
		while (it.hasNext()){
			Manejador manejador = it.next();
			if (manejador instanceof ManejadorObstaculos) {
				mo = (ManejadorObstaculos)manejador;
			}
		}
	}
	
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	public void mouseReleased(MouseEvent e) {
		try{
		Posicion pos = ((JLabelConPosicion)VistaJuego.ObtenerVistaJuego().getGrilla().getComponentAt((VistaJuego.ObtenerVistaJuego().getGrilla().getMousePosition(true)))).GetPosicion();
				
		CreadorObstaculo creadorP= new CreadorObstaculoPegote();
		mo.crearObstaculo(Juego.ObtenerJuego().getMapa().GetCasilleroXY(pos.getX(),pos.getY()), creadorP);
		}
		catch(RuntimeException re){}
	}

	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
